<!--
 * @Author: lixb
 * @Date: 2020-09-04 10:14:53
 * @LastEditTime: 2020-09-22 18:14:32
 * @Descripttion: 薪享卡对账管理
-->
<template>
  <div>
    <el-card class="title-search card-box">
      <div>
        <span>账期选择：</span>
        <el-date-picker
          v-model="billDate"
          type="month"
          value-format="yyyy-MM"
          placeholder="选择年月"
          :picker-options="disableFuture"
        ></el-date-picker>
      </div>
      <div>
        <el-button @click="resetDate">重置</el-button>
        <el-button type="primary" @click="queryList()">查询</el-button>
        <el-button type="primary" @click="exportExcel()">导出</el-button>
      </div>
    </el-card>
    <el-card class="main-card">
      <Table
        :table-data="tableData"
        :prop-data="propData"
        :table-index="true"
        :paging-data="pagingData"
        @getTableList="getTableList"
      >
        <template slot="op">
          <el-table-column prop="op" fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="detail(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
        </template>
      </Table>
    </el-card>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex';
  import Table from '@/components/Table';
  import { downloadBlob } from '@/utils/download';
  import { getAdvanceBillList, advanceBillExcelFile } from '@/api/careCard';
  export default {
    components: { Table },
    data() {
      return {
        disableFuture: {
          disabledDate: time => {
            return time.getTime() > new Date() - 3600 * 1000 * 24 * 30;
          },
        },
        billDate: '',
        tableData: [],
        propData: [
          {
            prop: 'billDate',
            label: '账期',
          },
          {
            prop: 'orderNumber',
            label: '订单总数',
          },
          {
            prop: 'orderAmount',
            label: '订单金额',
          },
          {
            prop: 'payType',
            label: '支付方式',
          },
          {
            prop: 'payAmount',
            label: '支付金额',
          },
          {
            prop: 'op',
            label: '操作',
            type: 'op',
          },
        ],
        pagingData: {
          total: 10,
          current: 1,
          size: 10,
        },
      };
    },
    computed: {
      ...mapGetters('user', ['userInfo']),
      organId() {
        return this.userInfo.organId;
      },
    },
    activated() {
      this.queryList();
    },
    methods: {
      queryList() {
        this.pagingData.current = 1;
        this.getTableList();
      },
      getTableList() {
        let params = {
          orgId: this.organId,
          billDate: this.billDate,
          current: this.pagingData.current,
          size: this.pagingData.size,
        };
        getAdvanceBillList(params).then(res => {
          if (res.status == 200) {
            this.tableData = res.data.records;
            this.pagingData.total = res.data.total;
          }
        });
      },
      resetDate() {
        this.billDate = '';
      },
      detail(row) {
        this.$router.push({
          path: '/careCard/reconciliationDetail',
          query: { id: row.id, date: row.billDate },
        });
      },
      async exportExcel() {
        const params = {
          billDate: this.billDate,
          current: this.pagingData.current,
          size: this.pagingData.size,
        };
        const res = await advanceBillExcelFile(params);
        downloadBlob(res.data, res.filename);
        this.$message.success('导出成功！');
      },
    },
  };
</script>
<style lang="scss" scoped>
  .title-search {
    div {
      display: inline-block;
      margin-right: 30px;
      span {
        color: #7f848b;
      }
    }
  }
  .main-card {
    margin-top: 20px;
  }
</style>
